<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, minimal-ui">
    <meta name="screen-orientation" content="portrait" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="full-screen" content="yes">
    <meta name="x5-fullscreen" content="true">
    <meta name="360-fullscreen" content="true" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <title>游戏</title>
    <script src="/config.js"></script>
    <style>
        html,
        body {
            margin: 0;
            padding: 0
        }

        .game-layer {
            -webkit-overflow-scrolling: touch
        }

        #tips {
            width: 100%;
            height: 100%;
            overflow: hidden;
            white-space: nowrap;
            text-align: center;
            position: relative;
            background: #f8fbff;
            overflow: hidden
        }

        @keyframes ghostUpdown {
            from {
                margin-top: -75px
            }

            to {
                margin-top: -35px
            }
        }

        @-webkit-keyframes ghostUpdown {
            from {
                margin-top: -75px
            }

            to {
                margin-top: -35px
            }
        }

        #tips .loading-img {
            width: 120px;
            position: absolute;
            top: 50%;
            left: 50%;
            -moz-transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            animation: ghostUpdown 1s infinite alternate;
            -webkit-animation: ghostUpdown 1s infinite alternate
        }

        #tips .loading-tip {
            color: #153c68;
            font-size: 16px;
            position: absolute;
            top: 50%;
            left: 50%;
            -moz-transform: translate(-50%, -50%);
            -ms-transform: translate(-50%, -50%);
            -webkit-transform: translate(-50%, -50%);
            transform: translate(-50%, -50%);
            margin-top: 30px
        }

        .game-box {
            width: 100%;
            height: 100vh
        }

        .game-iframe {
            width: 100%;
            height: 100%;
            padding: 0;
            margin: 0;
            border: 0;
            overflow: hidden
        }

        #gameIframe {
            position: absolute;
            margin-left: -50%
        }

        .fd_text {
            color: #fff;
            position: absolute;
            top: 45%;
            left: 15%;
        }

        .white_content {
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: 120;
        }

        .white_content .img_a {
            position: fixed;
            width: 1.5rem;
            height: 1.5rem;
            right: 1rem;
            top: 1rem;
            z-index: 122;
        }

        .img_a img {
            background-color: black;
        }

        .white_content img {
            width: 100%;
            height: 100%;
        }

        /* 弹框 */
        #share {
            position: absolute;
            top: 1%;
            right: 5%;
            width: 10rem;
            height: 3.5rem;
            display: none;
            z-index: 999;
        }

        #share img {
            width: 100%;
            height: 100%;
        }

        .cpContentbox {
            position: fixed;
            background-color: #fff;
            height: 100%;
            width: 100%;
            bottom: 0;
            z-index: 120;
        }

        .cpbg {
            position: absolute;
            width: 100%;
            bottom: 0;
            background-color: #fff;
            box-shadow: 0 0 10px #ccc;
        }

        .cpbg::after {
            content: '';
            position: absolute;
            top: -4px;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 10px;
            background: radial-gradient(circle, #fff, #fff 4px, transparent 5px);
            background-size: 10px 10px;
        }

        .cptitle {
            text-align: center;
        }

        .cptitle span {
            margin: 10px auto 5px;
            display: block;
            font-size: 18px;
            font-weight: bold;
            background-color: #ffffff;
            width: 150px;
        }

        .cptitle .line {
            border: 3px solid #086a6c;
            position: relative;
            width: 200px;
            margin: 0 auto;
            top: -20px;
            z-index: -1;
        }

        .cpContentbox p {
            margin: 0;
            font-size: 12px;
            text-align: center;
        }

        #copybox {
            position: relative;
            width: 150px;
            height: 2rem;
            line-height: 2rem;
            color: #fff;
            cursor: pointer;
            border-radius: 5px;
            background-color: #009966;
            margin: 10px auto 10px;
            text-align: center;
        }

        /* 弹框 */
        #tool-menu {
            z-index: 101;
            width: 55vw;
            max-width: 225px;
            height: auto;
            position: fixed;
            display: none;
            -webkit-overflow-scrolling: touch;
            top: 0;
            bottom: 0;
            overflow-y: scroll;
            overflow-x: hidden;
            /* justify-content: space-around; */
        }

        #tool-menu>div {
            width: 70%;
            padding: 5px 0;
            margin: 0 auto;
        }

        #tool-menu>div>img {
            width: 100%;
        }

        #tool-menu>.helper {
            /*margin: 20px 0 20px 0;*/
            margin: 20px auto;
        }

        #tool-menu>.game-ad {
            padding: 0;
            width: 90%;
            /*margin: 10px 0 0 0;*/
            margin: 10px auto;
            /*  padding: 10px 0 0 0;
            border-top: 1px dashed #EFAE4C; */
        }

        #tool-menu>.game-ad:last-of-type {
            /*margin: 3px 0 0 0;*/
            margin: 10px auto;
        }

        .tool-touch {
            width: 50px;
            height: 50px;
            opacity: .5;
            position: absolute;
            transition: all 0.5s ease 0s;
            z-index: 99;
        }

        /* 遮罩 */
        .black_overlay {
            display: none;
            position: absolute;
            top: 0%;
            left: 0%;
            width: 100vw;
            height: 100vh;
            z-index: 100;
            -moz-opacity: 0.8;
            opacity: .93;
            filter: alpha(opacity=88);
        }

        .black_overlay::before {
            content: '';
            top: -3px;
            left: -3px;
            background-color: black;
            border-radius: 0 15px 15px 0;
            border: 3px solid #ccc;
            width: 55vw;
            max-width: 225px;
            height: 100vh;
            position: fixed;
            color: #FFF;
        }

        #showCard {
            display: none;
            width: 100vw;
            height: 100vh;
            position: absolute;
        }

        .cardBody {
            top: calc(35vh - 160px);
            left: calc(50vw - 145px);
            background-color: RGB(96, 166, 224);
            border-radius: 12px;
            border: 3px solid #fff;
            width: 290px;
            size: 60vw;
            position: fixed;
            color: #FFF;
            z-index: 999;
        }

        .cardBody .avatar img {
            width: 50px;
            border-radius: 25px;
        }

        .cardBody .header {
            border-radius: 15px 15px 0 0;
            background: RGB(104, 171, 227);
            padding: 12px;
            height: 45px;
        }

        .cardBody .avatar {
            float: left;
        }

        .cardBody .userInfo {
            float: left;
            font-size: 14px;
            padding: 0 0 0 15px;
            width: 110px;
            overflow: hidden;
        }

        .cardBody .updatedMyCard1,
        .cardBody .updatedMyCard2 {
            float: right;
            text-align: center;
            font-size: 12px;
            /* margin: 5px 0 0 10px; */
            padding: 2px 5px;
            background: RGB(61, 162, 229);
            border-radius: 3px;
            border: 1px solid #fff;
        }

        .cardBody .updatedMyCard1 {
            margin: -2px 0 3px 0;
        }

        .cardBody input {
            width: 0;
            height: 0;
            opacity: 0;
        }

        .cardBody .cardContent img {
            width: 80%;
            padding: 10% 10% 5% 10%;
            border-radius: 5px;
            max-height: 280px;
        }

        .cardBody .cardContent .nul {
            width: 80%;
            height: 180px;
            padding: 10% 10% 5% 10%;
            font-size: 18px;
            text-align: center;
        }

        .cardBody .tips {
            font-size: 12px;
            text-align: center;
            padding-bottom: 15px;
        }

        .cardBody .tips .toggleCard {
            text-align: center;
            font-size: 14px;
            margin: 10px auto;
            width: fit-content;
            padding: 2px 5px;
            background: RGB(61, 162, 229);
            border-radius: 14px;
            border: 1px solid #fff;
        }

        #showCard .close {
            position: absolute;
            left: 129px;
            bottom: -50px;
            width: 32px;
            height: 32px;
            background: RGB(158, 213, 249);
            border-radius: 18px;
            border: 2px solid #fff;
            background-image: url(/hall/game/share/game_icon_close.png);
        }

        .tool-touch .img {
            animation-name: upAnimation;
            transform-origin: center bottom;
            animation-duration: 2s;
            animation-fill-mode: both;
            animation-iteration-count: infinite;
            animation-delay: .5s;
        }

        @keyframes upAnimation {
            0% {
                transform: rotate(0deg);
                transition-timing-function: cubic-bezier(0.215, .61, .355, 1)
            }

            10% {
                transform: rotate(-12deg);
                transition-timing-function: cubic-bezier(0.215, .61, .355, 1)
            }

            20% {
                transform: rotate(12deg);
                transition-timing-function: cubic-bezier(0.215, .61, .355, 1)
            }

            28% {
                transform: rotate(-10deg);
                transition-timing-function: cubic-bezier(0.215, .61, .355, 1)
            }

            36% {
                transform: rotate(10deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            42% {
                transform: rotate(-8deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            48% {
                transform: rotate(8deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            52% {
                transform: rotate(-4deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            56% {
                transform: rotate(4deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            60% {
                transform: rotate(0deg);
                transition-timing-function: cubic-bezier(0.755, .5, .855, .06)
            }

            100% {
                transform: rotate(0deg);
                transition-timing-function: cubic-bezier(0.215, .61, .355, 1)
            }
        }

        #cardFileLoading {
            text-align: center;
            position: absolute;
            width: 100%;
            background: #0e0e0ec7;
            height: 100%;
            top: 0;
            left: 0;
            border-radius: 6px;
            line-height: 25;
            display: none;
        }

        #browserOpen {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: #000;
            z-index: 9999;
            display: none;
        }

        #browserOpen img {
            position: relative;
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <div id="play-game-content">
        <div class="game-box">
            <!-- 弹框工具 -->
            <div class="tool-touch" id="tool-touch"
                style="width: 2.9rem;height: 2.9rem;z-index: 99;position: absolute;left: 0;top: 325px;display: none">
                <img id="touchImg" src="/attachment/vblog/210512113015_609b4bc71b3d0.png"
                    style="width: 100%;">
            </div>
            <div id="tool-menu"></div>
            <div id="light" class="white_content">
                <div class="img_a"
                    onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none';localStorage.removeItem('roomId')">
                    <img src="/hall/game/share/game_icon_close.png">
                </div>
                <!-- 二维码 -->
                <div class="qr_code" id="top"
                    style="width: 100%;height:80%;position: fixed;left: 0;top: 0;z-index: 121;">
                </div>
                <!-- 二维码 END -->
                <!-- 复制游戏短链地址 -->
                <div class="cpContentbox">
                    <div class="cpbg" id="wxcpbg">
                        <div class="cptitle">
                            <span>游戏快捷地址</span>
                            <div class="line"></div>
                        </div>
                        <p>复制后在群聊粘贴发送，点击地址即可进入游戏</p>
                        <div id="copybox" onclick="copyUrl()">
                            <textarea id="gameShareDescription"
                                style="position: absolute;left: -999px;width: 0;height: 0;"> </textarea>
                            <span>一键复制信息</span>
                        </div>
                    </div>
                </div>
                <!-- 复制游戏短链地址 END-->
            </div>
            <div id="fade" class="black_overlay">
            </div>
            <div id="showCard">

            </div>
            <!--右上角分享 部分游戏使用 -->
            <div id="share">
                <img src="/member/2019-06-17DahyrheWxk.png" alt="">
            </div>
            <!-- 浏览器打开 -->
            <div id="browserOpen">
                <img src="/hall/app/image/browser_open.png" alt="点右上角点开菜单在浏览器打开">
            </div>
            <!-- 弹框工具 END -->
            <div id="tips">
                <div id="loading">
                    <img src="/hall/test/game_loading.png" class="loading-img">
                    <span class="loading-tip">正在加载...</span>
                    <iframe id="gameIframe" class="game-iframe" src="" frameborder="no" border="0" marginwidth="0"
                        marginheight="0" scrolling="no"></iframe>
                </div>
            </div>
        </div>
    </div>
    <!-- <script src="//img.fphdcdn.com/hall/game/js/HandleError/FPHDHandleError.js"></script> -->
    <script src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="/hall/game/js/axios.min.js"></script>
    <script src="/hall/game/js/jquery-3.3.1.min.js"></script>
    <script src="/hall/game/js/touch.js"></script>
    <script src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js"></script>
    <script src="tool-touch/config.js"></script>
    <!-- <script src="https://img.fphdcdn.com/hall/game/js/vconsole.min.js"></script> -->
    <script>
        function hideWechatOptionMenu() {
            WeixinJSBridge.call('hideOptionMenu');
        }
        function onWechatReady() {
            if (typeof WeixinJSBridge == "undefined") {
                if (document.addEventListener) {
                    document.addEventListener('WeixinJSBridgeReady', hideWechatOptionMenu, false);
                } else if (document.attachEvent) {
                    document.attachEvent('WeixinJSBridgeReady', hideWechatOptionMenu);
                    document.attachEvent('onWeixinJSBridgeReady', hideWechatOptionMenu);
                }
            } else {
                try {
                    // onBridgeReady();
                    hideWechatOptionMenu();
                } catch (error) {
                    console.log(error);
                }
            }
        }
        var tools = {
            //加载js文件
            loadSingleScript: function (src, callback) {
                var s = document.createElement('script');
                s.async = false;
                s.src = src;
                s.addEventListener('load', function () {
                    s.parentNode.removeChild(s);
                    s.removeEventListener('load', arguments.callee, false);
                    callback && callback();
                }, false);
                document.body.appendChild(s);
            },
            //读取cookie，判断某个cookie是否存在。
            //读取操作配合 unclekeith=21; sex=boy 这个cookie会更好理解读取cookie的操作。
            getCookie: function (name) {
                var cookieName = encodeURIComponent(name) + "=",
                    cookieStart = document.cookie.indexOf(cookieName),
                    cookieValue = null;
                if (cookieStart > -1) {
                    var cookieEnd = document.cookie.indexOf(";", cookieStart);
                    if (cookieEnd == -1) {
                        cookieEnd = document.cookie.length;
                    }
                    cookieValue = decodeURIComponent(document.cookie.substring(cookieStart + cookieName.length,
                        cookieEnd));
                }
                return cookieValue;
            },
            //写入cookie。
            setCookie: function (name, value, expires, path, domain, secure) {
                var cookieText = encodeURIComponent(name) + "=" +
                    encodeURIComponent(value);
                if (expires instanceof Date) {
                    cookieText += "; expires=" + expires.toGMTString();
                }
                if (path) {
                    cookieText += "; path=" + path;
                }
                if (domain) {
                    cookieText += "; domain=" + domain;
                }
                if (secure) {
                    cookieText += "; secure";
                }
                document.cookie = cookieText;
            },
            //删除cookie
            unset: function (name, path, domain, secure) {
                tools.setCookie(name, "", new Date(0), path, domain, secure);
            },
            getQueryString: function (key) {
                var url = location.search || location.hash;
                var requestObj = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.slice(url.indexOf("?") + 1);
                    var strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        if (typeof requestObj[strs[i].split("=")[0]] == "undefined") requestObj[strs[i].split(
                            "=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
                    }
                }
                if (key == undefined) {
                    return requestObj;
                }
                return requestObj[key];
            },
            getUrlParam: function (url, key) {
                var requestObj = new Object();
                if (url.indexOf("?") != -1) {
                    var str = url.slice(url.indexOf("?") + 1);
                    var strs = str.split("&");
                    for (var i = 0; i < strs.length; i++) {
                        if (typeof requestObj[strs[i].split("=")[0]] == "undefined") requestObj[strs[i].split(
                            "=")[0]] = decodeURIComponent(strs[i].split("=")[1]);
                    }
                }
                if (key == undefined) {
                    return requestObj;
                }
                return requestObj[key];
            },
            getParaStringByData: function (data) {
                var para = "";
                for (var key in data) {
                    if (data[key] instanceof Array) {
                        for (var i = 0; i < data[key].length; i++) {
                            para += key + "[" + i + "]=" + data[key][i] + "&";
                        }
                    } else {
                        para += key + "=" + data[key] + "&";
                    }
                }
                para = para.substr(0, para.length - 1);
                return para;
            },
            gcGetPageSize: function () {
                var xScroll, yScroll;
                if (window.innerHeight && window.scrollMaxY) {
                    xScroll = window.innerWidth + window.scrollMaxX;
                    yScroll = window.innerHeight + window.scrollMaxY;
                } else {
                    if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
                        xScroll = document.body.scrollWidth;
                        yScroll = document.body.scrollHeight;
                    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
                        xScroll = document.body.offsetWidth;
                        yScroll = document.body.offsetHeight;
                    }
                }
                var windowWidth, windowHeight;
                if (self.innerHeight) { // all except Explorer
                    if (document.documentElement.clientWidth) {
                        windowWidth = document.documentElement.clientWidth;
                    } else {
                        windowWidth = self.innerWidth;
                    }
                    windowHeight = self.innerHeight;
                } else {
                    if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                        windowWidth = document.documentElement.clientWidth;
                        windowHeight = document.documentElement.clientHeight;
                    } else {
                        if (document.body) { // other Explorers
                            windowWidth = document.body.clientWidth;
                            windowHeight = document.body.clientHeight;
                        }
                    }
                }
                // for small pages with total height less then height of the viewport
                if (yScroll < windowHeight) {
                    pageHeight = windowHeight;
                } else {
                    pageHeight = yScroll;
                }
                // for small pages with total width less then width of the viewport
                if (xScroll < windowWidth) {
                    pageWidth = xScroll;
                } else {
                    pageWidth = windowWidth;
                }
                arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
                return arrayPageSize;
            }
        };

        var baseUrl, payUrl, ucApiUrl
        // 域名
        var domain = (window.location.host.split('.')[1]) + '.' + (window.location.host.split('.')[2])

        //匹配本地开发
        // if (domain == 'undefined.undefined' || domain == 168.1) {
        //domain = 'fpwan.com';
        domain = location.host;
        // }
        var urlHost = {
            'alpha': ['alpha-api.' + domain, 0],
            'beta': ['beta-api.' + domain, 0],
            'stable': ['api.' + domain, 1]
        }

        var protocol = location.protocol + '//'

        if (isLocal()) {
            baseUrl = protocol + urlHost.alpha[0]
            currentAmbient = urlHost.alpha[1]
            ucApiUrl = protocol + 'alpha-uc.' + domain;
        } else if (location.host.indexOf('beta') >= 0) {
            baseUrl = protocol + urlHost.beta[0]
            currentAmbient = urlHost.beta[1]
            ucApiUrl = protocol + 'beta-uc.' + domain;
        } else {
            // baseUrl = protocol + urlHost.stable[0]
            // currentAmbient = urlHost.stable[1]
            // ucApiUrl = protocol + 'uc.' + domain;

            baseUrl = JONO_HOST;
            currentAmbient = urlHost.stable[1]
            ucApiUrl = JONO_HOST;

        }

        var wxConfigUrl = ucApiUrl + '/WeChat/getJsConfig';
        var playApiUrl = baseUrl + '/Game/PlayApi';
        var shareUrl = baseUrl + '/XianLiao/GameSharing';
        var sharegameUrl = baseUrl + '/Game/GameShare';
        var HallConfigUrl = baseUrl + '/Hall/BaseConfig';
        var appId = tools.getQueryString('appId') || tools.getQueryString('appid');
        var channelId = tools.getCookie('HALLCHANNELID') || tools.getQueryString('channelId');
        var currentChannelId = tools.getQueryString('channelId');
        var token = tools.getQueryString('token') || tools.getCookie('HALLTOKEN') || tools.getCookie('token');
        var FPShareUser = tools.getQueryString('FPShareUser') || 0;
        var replaceData = {
            '{payUrl}': "",
            ext: 'payId',
            circleId: 'paiyouquanId',
            goodsId: 'taocanId'
        };
        var userId = 0;
        var judgeChannelAdapter = 0;

        var gameObj = {
            gameType: 0,
            toolTouchShow: false//默认不显示touch工具
        };

        //定位
        var geolocation = new qq.maps.Geolocation("W5ABZ-7FK3F-CVBJY-NAWQ3-YSX66-MABK5", "本地玩用户位置");
        var _getLocation, _getLocationSuccess = false;
        //分享内容
        window.updateShareData = {};

        toolTouch = {
            init: function () {
                axios({
                    method: 'post',
                    url: HallConfigUrl,
                    params: { 'channelId': channelId }
                }).then(function (res) {
                    if (res.data.code == 0 && res.status == 200) {
                        //var url = { 'homeUrl': res.data.data.homeUrl, 'hallUrl': res.data.data.hallUrl, 'gameHallUrl': res.data.data.gameHallUrl }
                        var url = { 'homeUrl': res.data.data.homeUrl, 'hallUrl': location.origin, 'gameHallUrl': location.origin + "/gamehall/index.html?channelId=" + channelId }
                        if (isInChannel() && isInApp() == false) {
                            gameObj.toolTouchShow = true;
                            touchMenu.createMenu(url)
                        }
                    }
                })
            },
            show: function () {
                if (tools.getCookie('clickTouchBar') == null) {
                    document.getElementById('touchImg').className = 'img';
                }
                document.getElementById('tool-touch').style.display = 'block';
            },
            hidden: function () {
                document.getElementById('tool-touch').style.display = 'none';
            }
        }
        touchMenu = {
            toolTouchMenuDefault: toolMenuConfig.default,
            toolTouchMenuChannel: toolMenuConfig.Channel(),
            createMenu: function (url) {
                var html = '', forData;
                forData = this.toolTouchMenuChannel[channelId] == undefined ? this.toolTouchMenuDefault : this.toolTouchMenuChannel[channelId];
                for (index = 0; index < forData.length; index++) {
                    if (forData[index].url && forData[index].type == 'link') {
                        forData[index].url = forData[index].url.replace('{homeUrl}', url.homeUrl);
                        forData[index].url = forData[index].url.replace('{hallUrl}', url.hallUrl);
                        forData[index].url = forData[index].url.replace('{gameHallUrl}', url.gameHallUrl);
                        forData[index].url = forData[index].url.replace('{channelId}', channelId);
                    }
                    html += "<div id='" + forData[index].id + "' class='" + forData[index].class + "' ><img src='" + forData[index].images + "' alt='" + forData[index].name + "' /></div>";
                }
                this.toolTouchMenuDefault = forData;
                document.getElementById('tool-menu').innerHTML = html;
                this.onWatchClick();
            },
            onWatchClick: function () {
                console.log("onWatchClick")
                this.toolTouchMenuDefault.forEach(function (element) {
                    var url = element.url;
                    document.getElementById(element.id).addEventListener('click', function (e) {
                        touchMenu.eventLog(element.id);
                        if (element.id == "share-gema") {
                            fphdFun.shareGame();
                        } else if (url && element.type == 'link') {
                            window.location.href = url;
                        }
                    })
                });
            },
            eventLog: function (event) {
                axios.get(baseUrl + '/Game/HelperEventLog', { params: { 'channelId': channelId, 'userId': userId, 'event': event, 'urlParams': document.location.search } })
                    .then(function (res) {
                        if (res.data.code !== 0) {
                            console.log(res);
                        }
                    })
            },
            show: function () {
                document.getElementById('fade').style.display = 'block';
                document.getElementById('tool-menu').style.display = 'block';
            },
            hidden: function () {
                document.getElementById('fade').style.display = 'none';
                document.getElementById('tool-menu').style.display = 'none';
            }
        }

        // var vConsole = new VConsole();

        //分享按钮拖动
        var ShareBoxLeft, ShareBoxRight, ShareBoxTimerId;
        mTouch('.tool-touch').on('swipestart', function () {
            clearTimeout(ShareBoxTimerId);
            this.style.transition = 'none';
            this.style['-webkit-transition'] = 'none';
            this.style.opacity = '.9';
            ShareBoxLeft = parseInt(this.style.left) || 0;
            assistiveTop = parseInt(this.style.top) || 0;
            return false;
        }).on('swiping', function (e) {
            this.style.left = ShareBoxLeft + e.mTouchEvent.moveX + 'px';
            this.style.top = assistiveTop + e.mTouchEvent.moveY + 'px';
        }).on('swipeend', function () {
            var el = this;
            var ShareBoxDiv = 50; //图标宽高
            var top = parseInt(el.style.top) || 0,
                left = parseInt(el.style.left) || 0,
                width = parseInt(el.offsetWidth) || 0,
                windowWith = (document.documentElement || document.body).offsetWidth,
                windowHeight = (document.documentElement || document.body).clientHeight;
            //处理相对靠左或右
            left = (left > (windowWith - width) / 2) ? (windowWith - width - 2) : 0;
            //动画效果
            el.style.transition = 'all .2s';
            el.style['-webkit-transition'] = 'all .2s';
            el.style.left = left + 'px';
            if (top > (windowHeight - ShareBoxDiv)) {
                top = (windowHeight - ShareBoxDiv);
            }
            //处理出界
            el.style.top = top < 0 ? 0 : top + 'px';
            // 滑动后 三秒不操作可见度修改
            ShareBoxTimerId = setTimeout(function () {
                el.style.transition = 'all .5s';
                el.style['-webkit-transition'] = 'all .5s';
                el.style.opacity = '.6';
            }, 3000);
        }).on('tap', function (el) {
            if (tools.getCookie('clickTouchBar') == null) {
                tools.setCookie('clickTouchBar', Date.parse(new Date()), new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1));
            }
            document.getElementById('touchImg').className = '';
            touchMenu.show();
        });
        mTouch('.black_overlay').on('tap', function () {
            touchMenu.hidden();
        });


        //异常捕捉
        // var HandleError = _window.FPHDHandleError;
        // HandleError.init({
        //     userId: tools.getCookie('userId'),
        //     channelId: tools.getQueryString('channelId')
        // });

        /**
         * 微信相关
         * @type {{audio: wxApiFun.audio, startRecord: wxApiFun.startRecord, stopRecord: wxApiFun.stopRecord, onVoiceRecordEnd: wxApiFun.onVoiceRecordEnd, playVoice: wxApiFun.playVoice, pauseVoice: wxApiFun.pauseVoice, stopVoice: wxApiFun.stopVoice, onVoicePlayEnd: wxApiFun.onVoicePlayEnd, uploadVoice: wxApiFun.uploadVoice, downloadVoice: wxApiFun.downloadVoice, translateVoice: wxApiFun.translateVoice, getNetworkType: wxApiFun.getNetworkType, getLocation: wxApiFun.getLocation}}
         */
        var wxApiFun = {
            audio: function (audioObj, func, failFunc, context) {
                if (wxApiFun.hasOwnProperty(audioObj.method)) {
                    wxApiFun[audioObj.method](audioObj, func, failFunc, context);
                } else {
                    console.warn(audioObj.method + 'is not exist.');
                }
            },

            // 开始录音
            startRecord: function (audioObj, func, failFunc, context) {
                wx.startRecord();
                if (func) {
                    func.call(context, 'start record ing');
                }
            },

            // 停止录音接口
            stopRecord: function (audioObj, func, failFunc, context) {
                wx.stopRecord({
                    success: function (res) {
                        func && func.call(context, res.localId);
                    },
                    fail: function (res) {
                        failFunc && failFunc.call(context, res);
                    }
                });
            },

            // 录音时间超过一分钟没有停止的时候会执行 complete 回调
            onVoiceRecordEnd: function (audioObj, func, failFunc, context) {
                wx.onVoiceRecordEnd({
                    complete: function (res) {
                        var localId = res.localId;
                        if (func) {
                            func.call(context, localId);
                        }
                    }
                });
            },

            // 播放语音接口
            playVoice: function (audioObj, func, failFunc, context) {
                wx.playVoice({
                    localId: audioObj.localId
                });
                if (func) {
                    func.call(context, 'play start done');
                }
            },

            // 暂停播放接口
            pauseVoice: function (audioObj, func, failFunc, context) {
                wx.pauseVoice({
                    localId: audioObj.localId
                });
                if (func) {
                    func.call(context, 'pause voice done');
                }
            },

            // 停止播放接口
            stopVoice: function (audioObj, func, failFunc, context) {
                wx.stopVoice({
                    localId: audioObj.localId
                });
                if (func) {
                    func.call(context, 'stop voice done');
                }
            },

            // 监听语音播放完毕接口
            onVoicePlayEnd: function (audioObj, func, failFunc, context) {
                wx.onVoicePlayEnd({
                    success: function (res) {
                        var localId = res.localId;
                        if (func) {
                            func.call(context, localId);
                        }
                    }
                });
            },

            // 上传语音接口
            uploadVoice: function (audioObj, func, failFunc, context) {
                // console.log('in upload voice');
                var result = {};
                wx.uploadVoice({
                    localId: audioObj.localId,
                    isShowProgressTips: audioObj.isShowProgressTips,
                    success: function (res) {
                        result.serverId = res.serverId;
                        result.localId = audioObj.localId;
                        if (func) {
                            func.call(context, result);
                        }
                    },
                    fail: function (res) {
                        if (failFunc) {
                            failFunc.call(context, res);
                        }
                    }
                });
            },
            // 下载语音接口
            downloadVoice: function (audioObj, func, failFunc, context) {
                var result = {};
                wx.downloadVoice({
                    serverId: audioObj.serverId,
                    isShowProgressTips: audioObj.isShowProgressTips,
                    success: function (res) {
                        result.serverId = audioObj.serverId;
                        result.localId = res.localId;
                        if (func) {
                            func.call(context, result);
                        }
                    },
                    fail: function (res) {
                        if (failFunc) {
                            failFunc.call(context, res);
                        }
                    }
                });
            },

            // 识别音频并返回识别结果接口
            translateVoice: function (audioObj, func, failFunc, context) {
                wx.translateVoice({
                    localId: audioObj.localId,
                    isShowProgressTips: audioObj.isShowProgressTips,
                    success: function (res) {
                        if (res.hasOwnProperty('translateResult')) {
                            func && func.call(context, res.translateResult);
                        } else {
                            failFunc.call(context, '无法识别');
                        }
                    }
                });
            },

            //获得网络状态
            getNetworkType: function (audioObj, func, context) {
                wx.getNetworkType({
                    success: function (res) {
                        func && func.call(context, res.networkType);
                    }
                });
            },

            getLocation: function (audioObj, func, context) {
                if (_getLocation == false) {
                    func && func.call(context, 'fail');
                } else {
                    func && func.call(context, _getLocation);
                }
            },
            share: function (shareObj, func, context) {
                var shareBox = {
                    title: shareObj.title,
                    desc: shareObj.desc,
                    link: shareObj.link,
                    imgUrl: shareObj.imgUrl,
                    success: function () {
                        if (func) {
                            func.call(context);
                        }
                    },
                    cancel: function () {
                        alert('取消了分享！')
                    }
                };
                if (isInWechat()) {
                    wx.ready(function () {
                        // wx.updateAppMessageShareData(shareBox);
                        // wx.updateTimelineShareData(shareBox);
                        wx.onMenuShareAppMessage(shareBox);
                        wx.onMenuShareTimeline(shareBox);
                        wx.error(function (res) {
                            console.log('wx ready error:');
                            console.log(res);
                        });
                    });
                }
            }
        }


        /**
         *  addEventListener message
         */
        window.addEventListener('message', function (event) {
            if (event == null || event.data == null) {
                return false;
            }
            //console.log(event.data);
            if (event.origin == 'https://apis.map.qq.com' && _getLocationSuccess == false) {
                _getLocation = {
                    accuracy: 65,
                    errMsg: "getLocation:ok",
                    horizontalAccuracy: 65,
                    latitude: event.data.lat,
                    longitude: event.data.lng,
                    speed: -1,
                    verticalAccuracy: 65,
                };
                _getLocationSuccess = true;
                // fphdFun.init();
            } else {
                if (event.data.action == null) {
                    return false;
                }
                var eventWhat = event.data.what;
                // console.log(event.data)
                switch (event.data.action) {
                    case 'pay':
                        fphdFun.goFPPay(event.data.payUrl);
                        break;

                    case 'audio':
                        wxApiFun.audio(event.data, function audioSucess(result) {
                            var audioSucessMessage = {};
                            audioSucessMessage.message = 'sucess';
                            audioSucessMessage.action = 'audio';
                            audioSucessMessage.method = event.data.method;
                            audioSucessMessage.result = result;
                            event.source.postMessage(audioSucessMessage, event.origin);
                        }, function audioFail(result) {
                            var audioFailMessage = {};
                            audioFailMessage.message = 'fail';
                            audioFailMessage.action = 'audio';
                            audioFailMessage.method = event.data.method;
                            audioFailMessage.result = result;
                            event.source.postMessage(audioFailMessage, event.origin);
                        });
                        break;

                    case 'share':
                        if (event.data.link != undefined) { //棋牌  比悦特殊处理
                            var _url = event.data.link.split('?');
                            event.data.link = location.origin + location.pathname + '?' + _url[1] + '&pid=' + appId +
                                '&FPShareUser=' + userId + '&j=1&test=1';
                            updateShareData = event.data;
                        } else if (event.data.data != undefined) { //h5
                            var _url = location.origin + location.pathname + '?channelId=' + channelId + '&appId=' +
                                appId + '&FPShareUser=' + userId + '&test=1';
                            if (typeof event.data.data.para == 'object' && Object.keys(event.data.data.para).length) {
                                _url += (_url.search("\\?") > 0 ? "&" : "?") + tools.getParaStringByData(event.data
                                    .data.para);
                            } else if (typeof event.data.data.para == 'string' && event.data.data.para.length) {
                                _url += '&' + event.data.data.para;
                            }
                            event.data.data.link = _url;
                            updateShareData = event.data.data;
                        };
                        //App分享标题
                        gameName = updateShareData.title.split('-')[1];
                        updateShareData.gameName = gameName == undefined ? updateShareData.title : gameName;
                        // fphdFun.shareGame(updateShareData);
                        if (ENV == "app") {
                            updateShareData.icon = updateShareData.imgUrl;
                            app_bridge.setShareInfo(updateShareData);
                        } else {
                            wxApiFun.share(updateShareData, function shareSuccess() {
                                var shareSuccessMessage = {};
                                shareSuccessMessage.message = 'success';
                                shareSuccessMessage.action = 'share';
                                shareSuccessMessage.result = 'share sucess';
                                event.source.postMessage(shareSuccessMessage, event.origin);
                            })
                        };
                        break;
                    case 'getNetworkType':
                        wxApiFun.getNetworkType(event.data, function getNetworkTypeResult(result) {
                            var _getNetworkTypeResult = {};
                            _getNetworkTypeResult.message = 'success';
                            _getNetworkTypeResult.action = 'getNetworkType';
                            _getNetworkTypeResult.result = result;
                            // console.log(_getNetworkTypeResult);
                            event.source.postMessage(_getNetworkTypeResult, event.origin);
                        });
                        break;
                    case 'getLocation':

                        wxApiFun.getLocation(event.data, function getLocationResult(result) {
                            var _getLocationResult = {};
                            _getLocationResult.message = 'success';
                            _getLocationResult.action = 'getLocation';
                            _getLocationResult.result = result;
                            // console.log(_getLocationResult);
                            event.source.postMessage(_getLocationResult, event.origin);
                        });

                        break;

                    case 'refreshPage':
                        location.reload();
                        break;

                    case 'getUrlData':
                        var _getUrlData = {};
                        _getUrlData.message = 'success';
                        _getUrlData.action = 'getUrlData';
                        _getUrlData.result = tools.getQueryString();
                        // console.log(_getUrlData);
                        event.source.postMessage(_getUrlData, event.origin);
                        break;
                    case 'stat':
                        console.log("stat")
                        //单独捕捉分享点击事件
                        if (eventWhat == 'showQR') {
                            fphdFun.shareGame();
                        }
                        break;
                    case "FPHDHandleError":
                        // HandleError.pushEvent(event.data.event);
                        break;
                    case "showCard":
                        userCard.showCard(event.data.user_id);
                        break;
                    default:
                        // console.log('->undefined '+ event.data.action);
                        break;
                }
            }
        }, false);

        window.fphdFun = {
            init: function () {
                if (!appId || !currentChannelId) {
                    document.getElementById('tips').innerHTML = '404！';
                    return;
                }
                if (currentChannelId != channelId) {
                    channelId = currentChannelId;
                    token = '';
                }
                if (appId == 699999) {
                    document.getElementById('gameIframe').setAttribute('scrolling', 'auto');
                    document.getElementById('play-game-content').setAttribute('class', 'game-layer');
                }
                if (tools.getQueryString('token')) {
                    token = tools.getQueryString('token');
                    var expires = new Date(new Date().getTime() + 86400 * 1000 * 7);
                    tools.setCookie('HALLTOKEN', token, expires, '/');
                    tools.setCookie('HALLCHANNELID', currentChannelId, expires, '/');
                    var _urlParamObj = tools.getQueryString();
                    if (typeof _urlParamObj['token'] != "undefined") {
                        delete _urlParamObj['token'];
                    }
                    window.location.replace(location.origin + location.pathname + '?' + tools.getParaStringByData(
                        _urlParamObj));
                }

                // if (!token) {
                return fphdFun.login();
                // }
                //请求游戏数据
                // fphdFun.getGameData();
            },
            login: function () {
                if (ENV == "app") {
                    fphdFun.appLogin();
                } else {
                    if (isInWechat()) {
                        FPHDSdk.login({
                            channelId: tools.getQueryString('channelId')
                        }, getUserInfo);
                    } else {
                        FPHDSdk.login({
                            channelId: tools.getQueryString('channelId'),
                            'login': 'phone'
                        }, getUserInfo);
                    };
                }
            },
            appLogin: function () {
                if (!token) {
                    var app_token;
                    var timer = setInterval(function () {
                        if (window.app_bridge.getWXToken()) {
                            app_token = window.app_bridge.getWXToken();
                            clearInterval(timer);
                            var para = encodeURIComponent(location.pathname.substr(1) + location.search);
                            location.href = baseUrl + "/Account/Native/Login?appToken=" + app_token + "&redirect=" + para + "&channelId=" + channelId;
                        }
                    }, 300)
                } else {
                    //请求游戏数据
                    fphdFun.getGameData();
                }
            },
            shareGame: function () {
                console.log("获取分享信息--shareGame")
                touchMenu.hidden();
                if (updateShareData.title == undefined || updateShareData.desc == undefined) {
                    alert('请稍后游戏未加载完！');
                    return false;
                } else {
                    document.getElementById('light').style.display = 'block';
                    $('.qr_code').html("<p style='text-align: center;color: #8a8a8a;font-size: 12px;padding: 40% 0;'>正在生成海报请稍后...</p>");
                    setTimeout(function () {
                        var shareJumpUrl = updateShareData.link;
                        if (channelId == 1005 && appId == 1002 && tools.getUrlParam(shareJumpUrl, 'NeverJump') == undefined) {
                            var nowTime = new Date();
                            var nowHours = nowTime.getHours();
                            //if (isInWechat() == true && nowHours >= 2 && nowHours <= 21) {
                            if (isInWechat() == true) {
                                shareJumpUrl = shareJumpUrl + '&NeverJump=1';
                            }
                            if (isInWechat() == false) {
                                shareJumpUrl = shareJumpUrl + '&NeverJump=1';
                            }
                        }
                        //console.log(shareJumpUrl);
                        var url = shareJumpUrl.split("?");
                        var theRequest = new Object();
                        theRequest['game_share_name'] = updateShareData.title;
                        theRequest['game_share_description'] = updateShareData.desc;
                        strs = url[1].split("&");
                        for (var i = 0; i < strs.length; i++) {
                            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                        }
                        theRequest['url'] = shareJumpUrl;
                        if (isInWechat()) { //如果是微信，隐藏拷贝分享按钮
                            document.getElementById('wxcpbg').style.display = 'none';
                            document.getElementById("top").style.top = "5%";
                        } else {
                            //短连
                            axios({ url: SHORT_URL, method: "post", params: { url: shareJumpUrl } }).then(function (res) {
                                document.getElementById('gameShareDescription').value = updateShareData.title + "\n" + updateShareData.desc + "\n 点击下方地址可直接进入游戏：\n" + res.data.data.url;
                            })
                        }
                        //请求分享二维码
                        axios({ method: 'post', url: sharegameUrl, params: theRequest }).then(function (res) {
                            if (res.data.data !== null) {
                                $('.qr_code').html("<img src='" + res.data.data.qr_code + "' id='qr'>");
                            }
                        })
                    }, 500);
                }
            },

            getWechatConfig: function () {

                // axios({
                //     method: 'get',
                //     url: wxConfigUrl,
                //     params: { channelId: channelId, token: token }
                // }).then(function (res) {
                //     data = res.data;
                //     var wx = window["wx"];
                //     if (!wx) {
                //         document.getElementById('tips').innerHTML = '微信接口没有初始化';
                //         console.error("微信接口没有初始化");
                //     } else {
                //         data.data.jsApiList = [
                //             'onMenuShareTimeline',
                //             'onMenuShareAppMessage',
                //             'previewImage',
                //             'hideOptionMenu',
                //             'showOptionMenu',
                //             'showAllNonBaseMenuItem',
                //             'hideAllNonBaseMenuItem',
                //             'closeWindow',
                //             'openAddress',
                //             "getNetworkType",
                //             "getLocation",
                //             "startRecord",
                //             "stopRecord",
                //             "onVoiceRecordEnd",
                //             "playVoice",
                //             "pauseVoice",
                //             "stopVoice",
                //             "onVoicePlayEnd",
                //             "uploadVoice",
                //             "downloadVoice",
                //             "translateVoice",
                //             "hideMenuItems"
                //         ];
                //         wx.config(data.data);
                //     }
                // }).catch(function (error) {
                // console.log(error.config);
                // document.getElementById('tips').innerHTML = error;
                // });
            },
            getGameData: function () {
                if (currentChannelId !== channelId) {//如果传渠道重新登录
                    return fphdFun.login();
                }
                var params = tools.getQueryString();
                if (params['channelId'] == undefined) {
                    params['channelId'] = channelId;
                }
                if (params['token'] == undefined) {
                    params['token'] = token;
                }
                if (params['appId'] == undefined) {
                    params['appId'] = appId;
                }
                axios({
                    method: 'get',
                    url: playApiUrl,
                    params: params,
                }).then(function (res) {
                    res = res.data;
                    var code = parseInt(res.code);
                    // console.log(res);
                    if (res.code == 10002) {
                        // alert("您好，您的账号被微信系统检测存在异常，暂时进行冻结，请联系微信官方咨询。");
                        location.replace('/tool/stop.html');
                        return;
                    }
                    if (code === 1888) {
                        location.href = res.data.url;
                        return;
                    }
                    if (code == 40029 || code == 510) {
                        tools.unset('HALLTOKEN')
                        fphdFun.login();
                        return false;
                    }
                    if (code > 0) {
                        if (code == 2) {
                            fphdFun.login();
                            return false;
                        }
                        document.getElementById('tips').innerHTML = res.message;
                        return;
                    }
                    //如果是微信调起环境钩子
                    if (isInWechat() == true) {
                        wechatHook(channelId);
                    }
                    gameObj.gameType = Number(res.data.gameType);
                    var expires = new Date(new Date().getTime() + 86400 * 1000 * 7);
                    tools.setCookie('userId', res.data.userId, expires, '/');
                    var _playUrl = res.data.playUrl;
                    var _currentUrl = location.href;
                    if (_playUrl.indexOf(location.protocol) == -1) {
                        ['http:', 'https:'].map(function (res) {
                            _currentUrl = _currentUrl.replace(res, _playUrl.substr(0, _playUrl.indexOf("//")))
                        });
                        document.location.replace(_currentUrl);
                    }
                    // document.getElementById('tips').remove();
                    if (channelId == 1005 && appId == 1002 && tools.getQueryString('NeverJump') == undefined) {
                        var nowTime = new Date();
                        var nowHours = nowTime.getHours();
                        var nowUrl = location.href;
                        var pattern = 'appid=([^&]*)';
                        var replaceText = 'appid=600028';
                        //var newUrl = nowUrl.match(pattern) ? nowUrl.replace(eval('/(appid=)([^&]*)/gi'), replaceText) : (nowUrl.match('[\?]') ? url + '&' + replaceText : nowUrl + '?' + replaceText);
                        var newUrl = nowUrl.replace(eval('/(appid=)([^&]*)/gi'), replaceText);
                        //if (isInWechat() == true && nowHours >= 2 && nowHours <= 21) {
                        if (isInWechat() == true) {
                            document.location.replace(newUrl);
                        }
                        if (isInWechat() == false) {
                            document.location.replace(newUrl);
                        }
                    }
                    document.title = res.data.title;
                    replaceData['{payUrl}'] = res.data.payUrl;
                    userId = res.data.userId;
                    judgeChannelAdapter = res.data.judgeChannelAdapter;
                    document.getElementById('gameIframe').setAttribute('src', _playUrl);

                }).catch(function (error) {
                    // console.log(error.config);
                    document.getElementById('tips').innerHTML = error;
                });
            },
            pageSize: function () {
                // 监听屏幕旋转事件
                var fphd_evt = "onorientationchange" in window ? "orientationchange" : "resize";
                var fphd_game_iframe = document.getElementById('gameIframe');
                var getPageSizeArr = tools.gcGetPageSize();
                window.addEventListener(fphd_evt, function () {
                    setTimeout(function () {
                        getPageSizeArr = tools.gcGetPageSize();
                        fphd_game_iframe.style.width = getPageSizeArr[2] + 'px';
                        fphd_game_iframe.style.height = getPageSizeArr[3] + 'px';
                    }, 100);
                });
                window.onresize = function () {
                    setTimeout(function () {
                        getPageSizeArr = tools.gcGetPageSize();
                        fphd_game_iframe.style.width = getPageSizeArr[2] + 'px';
                        fphd_game_iframe.style.height = getPageSizeArr[3] + 'px';
                    }, 100);
                };
                setTimeout(function () {
                    fphd_game_iframe.style.width = getPageSizeArr[2] + 'px';
                    fphd_game_iframe.style.height = getPageSizeArr[3] + 'px';
                }, 10);
            },
            goFPPay: function (payUrl) {
                if (judgeChannelAdapter) {
                    var _payUrl = payUrl;
                    Object.keys(replaceData).forEach(function (key) {
                        _payUrl = _payUrl.replace(key, replaceData[key]);
                    });
                    _payUrl = _payUrl + '&appId=' + appId + '&channelId=' + channelId + '&userId=' + userId +
                        '&from=2&redirectUrl=' + encodeURIComponent(location.href);
                    location.href = _payUrl;
                } else {
                    var _payUrl = payUrl;
                    replaceData.appOrderId = 'vendorOrderId';
                    replaceData['{payUrl}?'] = replaceData['{payUrl}'];
                    delete replaceData['{payUrl}'];
                    delete replaceData['ext'];
                    delete replaceData['goodsId'];
                    Object.keys(replaceData).forEach(function (key) {
                        _payUrl = _payUrl.replace(key, replaceData[key]);
                    });
                    _payUrl = _payUrl + '&gameId=' + appId + '&channelId=' + channelId + '&from=1';
                    location.href = _payUrl;
                }
            },
            getLocation: function () {
                // console.log('开始获取定位：' + new Date().getTime());
                if (isInWechat()) {
                    geolocation.getLocation(function (position) {
                        // console.log("h5定位成功");
                    }, function () {
                        _getLocation = false;
                        // console.log("h5定位失败");
                    }, 9000);

                } else {
                    geolocation.getIpLocation(function (position) {
                        // console.log("ip定位成功");
                    }, function () {
                        _getLocation = false;
                        // console.log("ip定位失败");
                    })
                }
                // console.log("结束获取定位" + new Date().getTime());
                setTimeout(function () {
                    if (_getLocationSuccess == false) {
                        _getLocationSuccess = true;
                        // console.log("定位超时直接进入");
                    } else {
                        // console.log("定位成功直接进入：setTimeout");
                    }
                }, 2600);
                // fphdFun.init();
            }
        }
        userCard = {
            showCard: function (userId) {
                axios({
                    method: 'get',
                    url: baseUrl + '/Game/GetUserCard',
                    params: { channelId: channelId, userIds: userId, responsType: 'json' },
                }).then(function (res) {
                    if (res.data.code == 0) {
                        var userInfo = res.data.data.users[0];
                        var htmlHeader = '<div class="cardBody"><div class="header"><div class="avatar"><img src="' + userInfo['user_avatar'] + '" /></div><div class="userInfo">I D：' + userInfo['user_id'] + '</br>昵称：' + userInfo['user_nickname'] + '</div>';
                        if (userInfo['user_id'] == tools.getCookie('userId')) {
                            htmlHeader = htmlHeader + '<div id="updatedMyCard1" class="updatedMyCard1" onclick="userCard.selectCardFile(1)">上传名片一</div><div id="updatedMyCard2" class="updatedMyCard2" onclick="userCard.selectCardFile(2)">上传名片二</div><input id="cardFile" type="file" name="card" onchange="userCard.uploadCardFile(this.files)"/><div id="cardFileLoading"></div></div>';
                        } else {
                            htmlHeader = htmlHeader + '<div id="updatedMyCard1" class="updatedMyCard1" onclick="userCard.toggleCard()">查看名片一</div><div id="updatedMyCard2" class="updatedMyCard2" onclick="userCard.toggleCard()">查看名片二</div></div>';
                        }
                        var htmlCard = '';
                        if (userInfo['card']['wechatPay']['status'] == 1) {
                            htmlCard = htmlCard + '<div id="wechatPay" class="cardContent"><img src="' + userInfo['card']['wechatPay']['url'] + '" /></div>';
                        } else {
                            htmlCard = htmlCard + '<div id="wechatPay" class="cardContent"><div class="nul">该用户还没有上传名片一</div> </div>';
                        }
                        if (userInfo['card']['aliPay']['status'] == 1) {
                            htmlCard = htmlCard + '<div id="aliPay" style="display:none;" class="cardContent"><img src="' + userInfo['card']['aliPay']['url'] + '" /></div>';
                        } else {
                            htmlCard = htmlCard + '<div id="aliPay" style="display:none;" class="cardContent"><div class="nul">该用户还没有上传名片二</div> </div>';
                        }
                        var tipsTxt = '(若名片有二维码可长按识别图中二维码)';
                        if (userInfo['user_id'] == tools.getCookie('userId')) {
                            var toggleCardHtml = '<div class="toggleCard" onclick="userCard.toggleCard()">切换查看名片</div>'
                            var htmlTips = '<div class="tips">' + toggleCardHtml + tipsTxt + '</div>';
                        } else {
                            var htmlTips = '<div class="tips">' + tipsTxt + '</div>';
                        }

                        var htmlClose = '<div class="close"  onclick="document.getElementById(\'showCard\').style.display=\'none\'" ></div> </div>';
                        document.getElementById('showCard').innerHTML = htmlHeader + htmlCard + htmlTips + htmlClose;
                        document.getElementById('showCard').style.display = 'block'
                    }
                }).catch(function (error) {
                    console.log(error);
                });
            },
            toggleCard: function () {
                if (document.getElementById('aliPay').style.display == 'none') {
                    document.getElementById('aliPay').style.display = 'block';
                    document.getElementById('wechatPay').style.display = 'none';
                } else {
                    document.getElementById('wechatPay').style.display = 'block';
                    document.getElementById('aliPay').style.display = 'none';
                }
            },
            selectCardFile: function (cardHow) {
                userCard.cardHow = cardHow;
                file = document.getElementById("cardFile");
                file.click();
            },
            cardHow: 1,
            catdUpdateLoding: '',
            uploadCardFile: function (file) {
                var fileType = ['image/png', 'image/jpeg', 'image/gif'];
                if (file) {
                    if (fileType.indexOf(file[0]['type']) == -1) {
                        alert('图片格式不正确,只能上传图片文件！');
                        return false;
                    }
                    document.getElementById("cardFileLoading").style.opacity = 1;
                    document.getElementById("cardFileLoading").style.display = 'block';
                    var dian = true;
                    userCard.intervalCardLoading = window.setInterval(function () {
                        document.getElementById("cardFileLoading").innerHTML = dian ? '正在上传中..&nbsp' : '正在上传中...';
                        dian = dian ? false : true;
                    }, 200);
                    axios.get(baseUrl + '/Extend/Oss/JsConfig?type=1', {}).then(function (res) {
                        if (res.data.code == 0) {
                            var resData = res.data.data;
                            var dateStr = new Date().toLocaleDateString()//获取时间年/月/日
                            var filePrefix = dateStr.replace(new RegExp("/", "g"), '-') + Math.random().toString(36).slice(-8);//随机年月日+字符串新文件名
                            var suffixLastStr = file[0]['name'].lastIndexOf('.');//获取文件名后缀
                            var fileSuffix = suffixLastStr != -1 ? file[0]['name'].substring(suffixLastStr) : '.jpg';
                            var fileNamePath = resData.dir + filePrefix + fileSuffix;//OSS图片路径
                            var url = resData.domain + '/' + fileNamePath;//完整图片地址
                            var formData = new FormData();//构建表单
                            formData.append('OSSAccessKeyId', resData.accessid);
                            formData.append('policy', resData.policy);
                            formData.append('signature', resData.signature);
                            formData.append('key', fileNamePath);
                            formData.append('success_action_status', '200');
                            formData.append('file', file[0]);
                            axios.post(resData.host, formData, { headers: { 'Content-Type': 'multipart/form-data' } }
                            ).then(function (resOss) {
                                if (resOss.status == 200) {
                                    userCard.pushUserCard(url);
                                } else {
                                    alert(resOss.statusText)
                                }
                            }).catch(function (errorOss) {
                                console.log(errorOss);
                            });
                        } else {
                            console.warn(res.data.message);
                        }
                    }).catch(function (error) {
                        console.log(error);
                    })
                }
            },
            pushUserCard: function (imgUrl) {
                axios.get(
                    baseUrl + '/Game/UpdateCard',
                    { params: { 'appid': appId, 'channelId': channelId, 'userId': tools.getCookie('userId'), 'token': token, 'responsType': "json", 'image': imgUrl, 'cardHow': userCard.cardHow } }
                ).then(function (res) {
                    clearInterval(userCard.intervalCardLoading);
                    if (res.data.code == 0) {
                        document.getElementById("cardFileLoading").innerHTML = '上传成功！';
                        cardLoadingOpacity = 1;
                        var timer = setInterval(function () {
                            cardLoadingOpacity -= 0.1;
                            document.getElementById("cardFileLoading").style.opacity = cardLoadingOpacity;
                            if (cardLoadingOpacity == 0) {
                                document.getElementById("cardFileLoading").style.display = 'none';
                            }
                        }, 100);
                        setTimeout(function () {
                            clearInterval(timer);
                            userCard.showCard(tools.getCookie('userId'));
                        }, 1000);

                    } else {
                        alert(res.data.message)
                    }
                }).catch(function (error) {
                    console.log(error);
                });
            }
        }

        gameTask = {
            gameIds: [600010, 600014, 600020],
            init: function () {
                // console.log('game task init')
                if (gameTask.gameIds.indexOf(Number(appId)) !== -1) {
                    // console.log('game task Have: gameId = ' + appId)
                    setTimeout(function () {
                        gameTask.isHaveTask();
                    }, 2000);
                }
            },
            isHaveTask: function () {
                var isHaveTask = FPHDTaskSdk.isHaveTask(5, 12, 3, appId);
                // console.log('game task isHaveTask => ' + isHaveTask);
                return isHaveTask == true ? FPHDTaskSdk.doTask(5, 12, 3, appId) : '';
            }
        }
        //强制浏览器渠道
        //var webChannels = [1010,1013];
        var webChannels = [];
        var jumpWebChannel = function () {
            function jumpWebChannel(channelId) {
                this.webChannel = [];
                this.setChannelWebUrl();
                if (isInWechat() == false) {
                    if (webChannels.indexOf(Number(channelId)) !== -1) {
                        return false;
                    }
                    if (window.location.host !== this.webChannel[channelId]) {
                        window.location.href = window.location.protocol + '//' + this.webChannel[channelId] + window.location.pathname + window.location.search;
                        return false;
                    }
                };
            }
            jumpWebChannel.prototype.setChannelWebUrl = function () {
                this.webChannel[1004] = LOCAL_DOMAIN;
                this.webChannel[1005] = LOCAL_DOMAIN;
                this.webChannel[1008] = LOCAL_DOMAIN;
                this.webChannel[1009] = LOCAL_DOMAIN;
                this.webChannel[1010] = LOCAL_DOMAIN;
                this.webChannel[1011] = LOCAL_DOMAIN;
                this.webChannel[1013] = LOCAL_DOMAIN;
                this.webChannel[1014] = LOCAL_DOMAIN;
                this.webChannel[1015] = LOCAL_DOMAIN;
                this.webChannel[1017] = LOCAL_DOMAIN;//玉林玩
                this.webChannel[1018] = LOCAL_DOMAIN;
                this.webChannel[1023] = LOCAL_DOMAIN;
                this.webChannel[1029] = LOCAL_DOMAIN;
                this.webChannel[1033] = LOCAL_DOMAIN;
                this.webChannel[1048] = LOCAL_DOMAIN;
            };
            return jumpWebChannel;
        }();

        //强制绑定手机号
        //var bindedChannels = [1010,1013, 1015, 1023, 1033];
        var bindedChannels = [];
        //微信环境钩子
        function wechatHook(channelId) {

            if (isInWechat() == true) {
                //如果是强制判断绑定手机渠道
                if (bindedChannels.indexOf(Number(channelId)) !== -1) {
                    isBindedWechat()
                }
                //如果是指定浏览器渠道弹窗引导
                if (webChannels.indexOf(Number(channelId)) !== -1) {
                    document.getElementById("browserOpen").style.display = 'block';
                    document.addEventListener('WeixinJSBridgeReady', function () { WeixinJSBridge.call('showOptionMenu'); }, false);
                    document.attachEvent('WeixinJSBridgeReady', function () { WeixinJSBridge.call('showOptionMenu'); });
                    return false;
                }
            }
        }

        function isBindedWechat() {
            axios({
                method: 'POST',
                url: ucApiUrl + "/user/getGlobalPhone",
                params: { channelId: channelId, token: token }
            }).then(function (res) {
                data = res.data;
                if (data.code > 0) {
                    window.location.href = location.origin + "/bindUser.html?channelId=" + channelId;
                }
            }).catch(function (error) {
                console.log(error.config);
            });
        }

        //UC登录回调
        function getUserInfo(data) {
            if (data.code > 0) {
                alert(data.msg)
                return false;
            }
            token = data.token;
            var expires = new Date(new Date().getTime() + 86400 * 1000 * 7);
            tools.setCookie('HALLTOKEN', data.token, expires, '/');
            fphdFun.getGameData();
            // gameTask.init();//活动相关
        }

        //先调起定位服务
        fphdFun.getLocation();

        //启动入口
        function start() {
            jumpWeb = new jumpWebChannel(channelId);
            fphdFun.init();
            fphdFun.pageSize();
            toolTouch.init();//初始化工具按钮
        }

        //判断运行环境，加载对应sdk文件
        var ENV = "other";
        if (isInApp()) {
            ENV = "app";
            tools.loadSingleScript("https://game.moitech.cn/app/app_bridge_v2.js", start);
            window.app_bridge.setNavType(1); //不要顶部切换渠道
        } else {
            if (isInWechat()) {
                // tools.loadSingleScript("https://res.wx.qq.com/open/js/jweixin-1.1.0.js", fphdFun.getWechatConfig);
            }
            tools.loadSingleScript("/sdk/fphdsdk.js?v=" + (new Date()).getTime(), start);
            //tools.loadSingleScript("/sdk/fphdtasksdk.js?v=" + (new Date()).getTime(), gameTask.init);
        }
        function isInApp() {
            return navigator.userAgent.indexOf('FPMessenger') !== -1;
        }

        function isInWechat() {
            return navigator.userAgent.indexOf('MicroMessenger') !== -1;
        }

        function isInXianliao() {
            return navigator.userAgent.indexOf('XLMessenger') !== -1;
        }

        function isInChannel(channel_id) {
            var WhiteListChannels = [1045, 1048, 1004, 1005, 1008, 1009, 1010, 1011, 1013, 1014, 1015, 1017, 1018, 1023, 1029, 1033];
            return WhiteListChannels.indexOf(Number(channel_id ? channel_id : channelId)) !== -1;
        }

        function isLocal() {
            return location.host.indexOf('alpha') >= 0 || location.host.indexOf('localhost') >= 0 || location.host.indexOf('192.168') >= 0 || location.host.indexOf('127.0.0') >= 0;
        }

        Object.defineProperties(gameObj, {
            'gameType': {
                set: function (value) {
                    console.log('gameType = ' + value);
                    value == 1 ? onWechatReady() : 0;
                    this._gameType = value;
                }, get: function () {
                    return this._gameType;
                }
            },
            'toolTouchShow': {
                set: function (value) {
                    console.log('toolTouchShow = ' + value);
                    value ? toolTouch.show() : toolTouch.hidden();
                    this._toolTouchShow = value;
                }, get: function () {
                    return this._toolTouchShow;
                }
            }
        });

        // 复制短链接
        function copyUrl() {
            document.getElementById('gameShareDescription').select()
            document.execCommand("copy");
            alert("复制成功,快去分享好友吧")
        }

    </script>

</body>

</html>
